package com.admin.business.portalWebsite.venusSysModelClassify;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 范本分类表
 * @create: 2023-11-18 16:45:42
 **/
@Service("venusSysModelClassifyService")
@Slf4j
public class VenusSysModelClassifyService{

    @Resource
    VenusSysModelClassifyDao venusSysModelClassifyDao;

    /**
     * 添加范本分类表,获取id数据
     *
     * @param cdoRequest - id:
     *                   - classify_id:父 id
     *                   - classify_name:类别名称
     *                   - classify_state:状态：0、启动，1、禁用，2、上架
     *                   - classify_grade:等级 0、一级，1、二级
     *                   - begin_time:开始时间
     *                   - update_time:更新时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return addVenusSysModelClassify(CDO cdoRequest) {
        venusSysModelClassifyDao.addVenusSysModelClassify(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新范本分类表数据
     *
     * @param cdoRequest - id:
     *                   - classify_id:父 id
     *                   - classify_name:类别名称
     *                   - classify_state:状态：0、启动，1、禁用，2、上架
     *                   - classify_grade:等级 0、一级，1、二级
     *                   - begin_time:开始时间
     *                   - update_time:更新时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return updateVenusSysModelClassifyById(CDO cdoRequest) {
        venusSysModelClassifyDao.updateVenusSysModelClassifyById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除范本分类表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return deleteVenusSysModelClassifyById(CDO cdoRequest){
        int count = venusSysModelClassifyDao.deleteVenusSysModelClassifyById(cdoRequest.getString("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除范本分类表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return deleteVenusSysModelClassify(CDO cdoRequest) {
        int count = venusSysModelClassifyDao.deleteVenusSysModelClassify(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取范本分类表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelClassifyById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysModelClassifyDao.getVenusSysModelClassifyById(cdoRequest.getString("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取范本分类表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelClassifyListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysModelClassifyDao.getVenusSysModelClassifyListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysModelClassifyDao.getVenusSysModelClassifyCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取范本分类表数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelClassifyListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysModelClassifyDao.getVenusSysModelClassifyListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysModelClassifyDao.getVenusSysModelClassifyCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
